<template>
  <div class="common-page f-c">
    <BackPage title="中介信息" />
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="中介名称：">
          <el-input v-model="searchParams.corporateName" clearable />
        </el-form-item>
        <el-form-item label="服务事项：">
          <el-select v-model="searchParams.serviceMattersId" clearable filterable>
            <el-option v-for="item in options" :key="item.id" :value="item.id" :label="item.serviceMatters" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form inline>
        <el-form-item>
          <el-button type="primary" @click="onAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-box f-g">
      <el-table
        v-loading="loading"
        height="100%"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column label="中介名称" min-width="200px">
          <template slot-scope="scope">
            <div class="f-r a-c">
              <img v-if="scope.row.isBlack == 1" src="@/assets/black.jpg" style="width: 30px;height: 30px" alt="">
              <span>{{ scope.row.corporateName }}</span>
            </div>
          </template>
        </el-table-column>

        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="160px">
          <template slot-scope="scope">
            <el-button type="text" @click="onRead(scope.row)">查看详情</el-button>
            <el-button type="text" @click="onApp(scope.row)">查看评价</el-button>
            <el-button type="text" @click="onServeEvent(scope.row)">服务事项</el-button>
            <el-button type="text" @click="onEdit(scope.row)">编辑黑榜</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <BaseInfoAdd ref="BaseInfoAddRef" @get-page="initData" />
    <APList ref="APListRef" />
    <ServeEvent ref="ServeEventRef" />
    <el-dialog
      title="设置黑榜"
      :visible.sync="dialogValue"
      width="500px"
      append-to-body
    >
      <el-form label-width="120px">
        <el-form-item label="是否黑榜：">
          <el-select v-model="ruleForm.isBlack" clearable placeholder="请选择">
            <el-option :value="0" label="否" />
            <el-option :value="1" label="是" />
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onSave">确 定</el-button>
        <el-button @click="dialogValue = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import BaseInfoAdd from './base-info-add'
import APList from './ap-list'
import ServeEvent from './serve-event'
import { http_intermediary_info, http_intermediary_serveevent } from '@/api'
export default {
  name: 'Index',
  components: {
    BaseInfoAdd,
    APList,
    ServeEvent
  },
  mixins: [crud],
  data() {
    return {
      request: http_intermediary_info,
      searchParams: {
        corporateName: '',
        serviceMattersId: ''
      },
      columns: [
        { prop: 'creditCode', label: '单位代码' },
        { prop: 'contactsName', label: '中介联系人' },
        { prop: 'contactsPhone', label: '中介联系人手机' },
        { prop: 'officeLocation', label: '办公地址' }
      ],
      tableData: [
      ],
      ruleForm: {
        id: '',
        isBlack: 0
      },
      options: []
    }
  },
  created() {
    http_intermediary_serveevent.allList().then(res => {
      this.options = res.data
    })
  },
  methods: {
    onRead(item) {
      this.$refs.BaseInfoAddRef.read(item)
    },
    onServeEvent(item) {
      this.$refs.ServeEventRef.open(item)
    },
    onApp(item) {
      this.$refs.APListRef.open(item)
    },
    onAdd() {
      this.$refs.BaseInfoAddRef.open()
    },
    onEdit(item) {
      this.ruleForm.id = item.id
      this.ruleForm.isBlack = item.isBlack || 0
      this.dialogValue = true
    },
    onSave() {
      http_intermediary_info.set_status(this.ruleForm).then(res => {
        this.$message.success(res.msg)
        this.dialogValue = false
        this.initData()
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
